#include<bits/stdc++.h>
using namespace std;
double Q[1000010], R[1000010];
double a[1000010], b[1000010];
const double eps = 1e-8;

void slove(int max_a, int max_b){
    for(int i=max_a; i>=max_b; i--){
        if(fabs(a[i]) > eps){
            double c = a[i]/b[max_b];
            Q[i-max_b] = c;

            for(int j=max_b; j>=0; j--){
                if(fabs(b[j])>eps)
                    a[i-max_b+j] -= c * b[j];
            }
        }
    }
    memcpy(R, a, sizeof(a));
    return;
}

int main(){
    int max_a=0, max_b=0, x, y;
    int index;
    cin>>index;
    for(int i=0; i<index; i++){
        cin>>x>>y;
        a[x] = y;
        max_a = max(x, max_a);
    }
    cin>>index;
    for(int i=0; i<index; i++){
        cin>>x>>y;
        b[x] = y;
        max_b = max(x, max_b);
    }
    slove(max_a, max_b);

    //统计个数
    int cnt_q=0, cnt_r=0;
    for(int i=max_a; i>=0; i--){
        if(abs(Q[i])>0.0445) cnt_q++;
        if(abs(R[i])>0.0445) cnt_r++;
    }

    //输出
    if(cnt_q!=0){
        cout<<cnt_q;
        for(int i=max_a-max_b; i>=0; i--)
            if(abs(Q[i])>0.0445)
                printf(" %d %.1lf", i, Q[i]);
    }
    else
        cout<<"0 0 0.0";
    cout<<endl;

    if(cnt_r!=0){
        cout<<cnt_r;
        for(int i=max_b-1; i>=0; i--)
            if(abs(R[i])>0.0445)
                printf(" %d %.1lf", i, R[i]);
    }
    else
        cout<<"0 0 0.0";

    return 0;
} 